package com.mach.platform.security;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.mach.platform.utils.ReqStatus;
import lombok.Cleanup;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @Description:  退出返回 json指令
 * @Package: com.mach.platform.security
 * @Info Anonymous create on 2018/02/02 15:18
 */
public class CuLogoutSuccessHandler implements LogoutSuccessHandler {

	@Override
	public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {

		response.setContentType("application/json;charset=utf-8");
		@Cleanup PrintWriter out = response.getWriter();
		Map map = Maps.newHashMap();
		map.put("status", ReqStatus.LOGOUT.getValue());
		map.put("msg", "退出到登录界面！");
		out.write(JSON.toJSON(map).toString());
	}
}
